package com.daiqile.myinterest.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Handler;
import android.support.v4.app.ActivityCompat;
import android.support.v4.app.ActivityOptionsCompat;
import android.view.KeyEvent;
import android.view.View;
import android.widget.Button;

import com.daiqile.myinterest.BaseActivity;
import com.daiqile.myinterest.R;
import com.daiqile.myinterest.model.SVGbean;
import com.jaredrummler.android.widget.AnimatedSvgView;
import com.vondear.rxtools.RxBarTool;

import butterknife.BindView;
import butterknife.OnClick;

public class SVGActivity extends BaseActivity {


    @BindView(R.id.animated_svg_view)
    AnimatedSvgView animatedSvgView;
    @BindView(R.id.btn_svg_login)
    Button btnSvgLogin;
    @BindView(R.id.btn_svg_register)
    Button btnSvgRegister;
    Activity mActivity;

    @Override
    protected int getContentView() {
        return R.layout.activity_svg;
    }

    @Override
    protected void initView() {
        mActivity = SVGActivity.this;
        RxBarTool.setTransparentStatusBar(this);
        setSvg(SVGbean.values()[4]);
        initButton();
    }

    private void initButton() {
        new Handler().postDelayed(new Runnable(){
            public void run() {
                btnSvgLogin.setVisibility(View.VISIBLE);
                btnSvgRegister.setVisibility(View.VISIBLE);
            }
        }, 2000);
    }

    private void setSvg(SVGbean svGbean) {
        animatedSvgView.setGlyphStrings(svGbean.glyphs);
        animatedSvgView.setFillColors(svGbean.colors);
        animatedSvgView.setViewportSize(svGbean.width, svGbean.height);
        animatedSvgView.setTraceResidueColor(0x32000000);
        animatedSvgView.setTraceColors(svGbean.colors);
        animatedSvgView.rebuildGlyphData();
        animatedSvgView.start();
    }
    /**
     * 屏蔽物理返回按钮
     * @param keyCode
     * @param event
     * @return
     */
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if(keyCode== KeyEvent.KEYCODE_BACK){
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }

    @OnClick({R.id.btn_svg_login, R.id.btn_svg_register})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.btn_svg_login:
                ActivityOptionsCompat compat = ActivityOptionsCompat.makeSceneTransitionAnimation(mActivity,btnSvgLogin,"login");
                Intent intent = new Intent(mActivity, LoginActivity.class);
                ActivityCompat.startActivity(mActivity, intent, compat.toBundle());

                break;
            case R.id.btn_svg_register:
                startActivity(new Intent(SVGActivity.this,MainViewActivity.class));
                finish();
                break;
        }
    }
}
